/*
 * Copyright 2014 OGIS-RI All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package jp.co.ogis_ri.optaplanner.vehiclerouting.domain;

import jp.co.ogis_ri.optaplanner.vehiclerouting.domain.core.ChainedTimeWindowedStep;
import jp.co.ogis_ri.optaplanner.vehiclerouting.domain.core.TimeWindowedStep;

/**
 * 休憩
 * 
 */
public class Break extends ChainedTimeWindowedStep {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * 休憩時間
	 */
	protected int breakTime;

	/**
	 * 休憩時間を取得する
	 * 
	 * @return
	 */
	public int getBreakTime() {
		return this.breakTime;
	}

	/**
	 * 休憩時間を設定する
	 * 
	 * @param breakTime
	 */
	public void setBreakTime(final int breakTime) {
		this.breakTime = breakTime;
	}

	/**
	 * 
	 */
	@Override
	public Integer getDepartureTime() {
		if (arrivalTime == null) {
			return null;
		}

		// 到着時間に休憩時間を足すと出発時間
		return arrivalTime + breakTime;
	}

	@Override
	public Location getLocation() {

		// 休憩はその場所で取るので、ひとつ前のLocationを返してあげる
		return this.getPreviousStep().getLocation();
	}

	@Override
	public int getDistanceToPreviousStep() {

		// 休憩は移動は必要ないので
		return 0;
	}

	@Override
	public int getTravelTimeToPreviousStep() {

		// 休憩は移動時間は必要ないので
		return 0;
	}

	@Override
	public int getDistanceTo(final TimeWindowedStep step) {

		// 同じ地点の場合、移動距離は０になる
		if (this.getLocation() == step.getLocation()) {
			return 0;
		}

		return this.getLocation().getDistance(step.getLocation());
	}

	@Override
	public int getTravelTimeTo(final TimeWindowedStep step) {

		// 同じ地点の場合、移動時間は０になる
		if (this.getLocation() == step.getLocation()) {
			return 0;
		}

		return this.getLocation().getTravelTime(step.getLocation());
	}

}
